diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 04e430a42e..02e3295246 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -126,9 +126,9 @@ class SQLCompiler:
             for col in cols:
                 expressions.append(col)
         for expr, (sql, params, is_ref) in order_by:
-            # Skip References to the select clause, as all expressions in the
-            # select clause are already part of the group by.
-            if not is_ref:
+            # Skip References to the select clause and Random expressions, as all expressions in the
+            # select clause are already part of the group by and Random should not be included.
+            if not is_ref and not isinstance(expr, Random):
                 expressions.extend(expr.get_group_by_cols())
         having_group_by = self.having.get_group_by_cols() if self.having else ()
         for expr in having_group_by:
